﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Videos.aspx.cs" Inherits="Enterprise.Admin.Videos" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../Content/Widget/fancyBox/jquery.fancybox.css" rel="stylesheet" />
    <link href="../Content/Widget/kindeditor/plugins/code/prettify.css" rel="stylesheet" />
    <link href="../Content/Widget/uploadify/uploadify.css" rel="stylesheet" />

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_video">
        <form id="search_video_form" action="Handle/Video/GetListJson.aspx" method="get">
            <p>
                <label>分类：</label><input id="search_video_category_id" name="CoVideoCategoryId" />
            </p>
            <p>
                <label>视频名称：</label><input type="text" name="CoName" />
            </p>
            <p class="multi-language">
                <label>语言：</label><select name="CoLanguage" class="easyui-combobox">
                    <option value="">全部</option>
                    <option value="zh_cn">简体中文</option>
                    <option value="en_us">美国英语</option>
                </select>
            </p>
        </form>
    </div>
    <div id="add_video">
        <form id="add_video_form" action="Handle/Video/Add.aspx">
            <div id="add_video_tabs" style="padding: 0px; height: auto">
                <div title="基础资料">
                    <p>
                        <label>分类：</label><input id="add_video_category_id" name="CoVideoCategoryId" />
                    </p>
                    <p>
                        <label>视频名称：</label><input type="text" name="CoName" />
                    </p>
                    <p>
                        <label>封面图片：</label><span id="Span1"><input type="file" id="add_upload" name="Filedata" /></span>
                    </p>
                    <p>

                        <label style="height: 70px; line-height: 70px;">关键字：</label><textarea rows="" cols="" style="width: 300px; height: 60px" name="CoKeyWord"></textarea>

                    </p>
                    <p>
                        <label style="height: 70px; line-height: 70px;">描述：</label><textarea rows="" cols="" style="width: 300px; height: 60px" name="CoDescription"></textarea>
                    </p>
                    <p>
                        <label>创建日期：</label><input type="text" name="CoDate" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") %>" class="easyui-datetimebox" />
                    </p>
                    <p class="multi-language">
                        <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                            <option value="zh_cn">简体中文</option>
                            <option value="en_us">美国英语</option>
                        </select>
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="true" />

                    </p>
                </div>
                <div title="视频内容" style="height: 100%">
                    <textarea rows="" cols="" name="CoContent" id="add_video_content"></textarea>
                </div>
            </div>
        </form>
    </div>
    <div id="edit_video">
        <form id="edit_video_form" action="Handle/Video/Edit.aspx">
            <div id="edit_video_tabs" style="padding: 0px; height: auto">
                <div title="基础资料">
                    <p>
                        <label>分类：</label><input id="edit_video_category_id" name="CoVideoCategoryId" />
                        <input id="edit_video_id" name="CoVideoId" type="hidden" value="" />
                    </p>

                    <p>
                        <label>视频名称：</label><input type="text" name="CoName" value="" />
                    </p>
                    <p>
                        <label>封面图片：</label><span id="edit_upload_box"><input type="file" id="edit_upload" name="Filedata" /></span>
                    </p>
                    <p>

                        <label style="height: 70px; line-height: 70px;">关键字：</label><textarea rows="" cols="" style="width: 300px; height: 60px" name="CoKeyWord"></textarea>

                    </p>
                    <p>
                        <label style="height: 70px; line-height: 70px;">描述：</label><textarea rows="" cols="" style="width: 300px; height: 60px" name="CoDescription"></textarea>
                    </p>
                    <p>
                        <label>创建日期：</label><input type="text" id="edit_date" name="CoDate" value="" class="easyui-datetimebox" />
                    </p>

                    <p>
                        <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                            <option value="zh_cn">简体中文</option>
                            <option value="en_us">美国英语</option>
                        </select>
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="true" />

                    </p>
                </div>
                <div title="视频内容" style="height: 100%">
                    <textarea rows="" cols="" name="CoContent" id="edit_video_content"></textarea>
                </div>
            </div>
        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '视频列表',
                fit: true,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                fitColumns: true,
                url: 'Handle/Video/GetListJson.aspx',
                idField: 'id',
                singleSelect: true,
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                }, onLoadSuccess: function () {
                    $(".fancybox_image").fancybox({
                        'transitionIn': 'none',
                        'transitionOut': 'none',
                        'titlePosition': 'over'
                    });
                },
                columns: [[
                         { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                         { title: '视频名称', field: 'CoName', width: 280, align: 'center' },
                         { title: '创建日期', field: 'CoDate', width: 180, align: 'center' },
                         { title: '分类', field: 'CoCategoryName', width: 100, align: 'center' },
                         {
                             title: '语言', field: 'CoLanguage', width: 100, align: 'center',
                             formatter: function (value) {
                                 var text;
                                 $.each(languageData, function () {
                                     if (this.id == value) {
                                         text = this.text;
                                         return false;
                                     }
                                     return true;
                                 });
                                 return text;
                             }
                         }, {
                             field: 'CoNormalImage', title: '图片', width: 80, align: 'center',
                             formatter: function (value, rowData) {
                                 return '<a class="fancybox_image" href="../upload/video/image/' + rowData.CoNormalImage + '"></a>';
                             }
                         }, {
                             field: 'CoFileUrl', title: '视频查看', width: 80, align: 'center',
                             formatter: function (value, rowData) {
                                 return '<a class="fancybox_image" href="' + rowData.CoFileUrl + '"></a>';
                             }
                         },
                    {
                        field: 'CoIsRecommend', title: '推荐', width: 60, align: 'center',
                        formatter: function (value) {
                            return value ? '是' : '否';
                        }
                    },

                       {
                           title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                               return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                           }
                       },
                        {
                            title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                            }
                        }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }

                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }

                }, {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search_video').dialog("open");
                    }

                }]
            });
            $('#add_video').dialog({
                title: '添加视频',

                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addVideoContent.sync();
                        addSave(function () { });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_video').dialog('close');
                    }
                }]

            });
            $('#edit_video').dialog({
                title: '修改视频',

                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editVideoDescription.sync();
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_video').dialog('close');
                    }
                }]
            });
            $('#search_video').dialog({
                title: '检索视频',

                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_video_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_video').dialog('close');
                    }
                }]
            });
            $('#edit_video_form').form({
                onBeforeLoad: function () {
                },
                onLoadSuccess: function (data) {
                    editVideoDescription.html(data.CoContent);
                    $('#edit_date').datetimebox('setValue', data.CoDate);
                    $('#edit_video').dialog("open");
                },
                onLoadError: function () {
                }
            });
            $('#add_video_tabs').tabs({
                border: false
            });
            $('#edit_video_tabs').tabs({
                border: false
            });
            var addVideoContent = window.KindEditor.create('#add_video_content', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '688px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            var editVideoDescription = window.KindEditor.create('#edit_video_content', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '688px',
                height: '375px',
                filterMode: false,
                allowFileManager: true, afterCreate: function () {

                }
            });
            $.ajax({
                type: "POST",
                url: "Handle/VideoCategory/GetTreeJson.aspx",
                success: function (data) {
                    var searchData = data.concat();;

                    $('#add_video_category_id').combotree({
                        data: data
                    }); $('#edit_video_category_id').combotree({
                        data: data
                    });
                    searchData.unshift({ id: '', text: '全部' });
                    $('#search_video_category_id').combotree({
                        data: searchData
                    });
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '删除失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });

        });

        function edit(id) {
            $('#edit_video_form').form('load', 'Handle/Video/GetDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/Video/Delete.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }

            });

        }
        function add() {
            $('#add_video').dialog("open");
        }
        //添加保存
        function addSave() {
            $.ajaxFileUpload({
                type: "POST",
                fileElementId: 'add_upload',
                dataType: 'json',
                data: $('#add_video_form').serializeObject(),
                url: "Handle/Video/Add.aspx",
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                        $('#add_video_form')[0].reset();
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //编辑保存
        function editSave() {
            $.ajaxFileUpload({
                type: "POST",
                fileElementId: 'edit_upload',
                dataType: 'json',
                data: $('#edit_video_form').serializeObject(),
                url: "Handle/Video/Edit.aspx",
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $("#table_list").datagrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
    <script src="../Content/Widget/fancyBox/jquery.fancybox.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.mousewheel.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.easing.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/kindeditor-min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/plugins/code/prettify.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/uploadify/jquery.uploadify.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/jquery.json.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/AjaxFileUploader/ajaxfileupload.js" charset="utf-8" type="text/javascript"></script>

</asp:Content>
